﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMALLERP.DataClass;
using SMALLERP;
using SMALLERP.QM;

namespace XJLSC.QM
{
    public partial class QMSCHAXUN : Form
    {
        private readonly DataBase db = new DataBase();
        public delegate void Cdgzzx(object sender, EventArgs e);
        //定义委托对象
        public Cdgzzx cdgzzx;
        public QMSCHAXUN()
        {
            InitializeComponent();
        }

        private void QMSCHAXUN_Load(object sender, EventArgs e)
        {
            string strSql = "";
            if (QJCX.LX == "查看检验结果")
            {
                if (QJCX.DB == "IQC")
                {
                    strSql = "SELECT TA001 单别,TA002 单号,TA003 序号,TA004 检验日期,TAC01 验收数量,ISNULL(QMSTA.UDF01,'') 检验结果,TA026 次数,TA015 备注,INVMB.UDF01 老编码 FROM QMSTA LEFT JOIN PURCD ON TA001=CD001 AND TA002=CD002 AND TA003=CD003 LEFT JOIN INVMB ON CD004=MB001 WHERE CD004='" + QJCX.PH + "' AND TA004>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.QSRQ + "'),112) AND TA004<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.JZRQ + "'),112)";
                }

                if (QJCX.DB == "FQC")
                {
                    strSql = "SELECT A.TA001 单别,A.TA002 单号,A.TA003 序号,A.TA004 检验日期,A.TAC01 验收数量,ISNULL(A.UDF01,'') 检验结果,A.TA026 次数,A.TA015 备注,INVMB.UDF01 老编码 FROM QMSTA A LEFT JOIN MOCTA B ON A.TA001=B.TA001 AND A.TA002=B.TA002 LEFT JOIN INVMB ON B.TA006=MB001 WHERE B.TA006='" + QJCX.PH + "' AND A.TA004>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.QSRQ + "'),112) AND A.TA004<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.JZRQ + "'),112)";
                }

                if (QJCX.DB == "OQC")
                {
                    strSql = "SELECT TA001 单别,TA002 单号,TA003 序号,TA004 检验日期,TAC01 验收数量,ISNULL(QMSTA.UDF01,'') 检验结果,TA026 次数,TA015 备注,TN004 客户编号 FROM QMSTA LEFT JOIN COPTO ON TA001=TO001 AND TA002=TO002 AND TA003=TO003 LEFT JOIN COPTN ON TO001=TN001 AND TO002=TN002 WHERE TO007='" + QJCX.PH + "' AND TA004>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.QSRQ + "'),112) AND TA004<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.JZRQ + "'),112)";
                }

                if (QJCX.DB == "PQC")
                {
                    strSql = "SELECT A.TA001 单别,A.TA002 单号,A.TA003 序号,A.TA004 检验日期,A.TAC01 验收数量,ISNULL(A.UDF01,'') 检验结果,A.TA026 次数,A.TA015 备注,INVMB.UDF01 老编码 FROM QMSTA A LEFT JOIN MOCTG B ON A.TA001=B.TG001 AND A.TA002=B.TG002 AND A.TA003=B.TG003 LEFT JOIN INVMB ON B.TG004=MB001 WHERE B.TG004='" + QJCX.PH + "' AND A.TA004>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.QSRQ + "'),112) AND A.TA004<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.JZRQ + "'),112)";
                }
                if (QJCX.DB == "综合")
                {
                    strSql = "SELECT TL010 日期,UDF02 责任部门,UDF01 供应商,TE017 品号,TE018 品名,TE019 规格,SCGY 工序,TL006 数量 FROM V_SCGY WHERE RTRIM(UDF02)+RTRIM(UDF01)='" + QJCX.PH + "' AND TL010=CONVERT(CHAR(8),DATEADD(DAY,0,'" + QJCX.QSRQ + "'),112)";
                }
                this.Width = 800;
                this.Height = 400;
            }

           
            try
            {
                dataGridView1.DataSource = "";
                dataGridView1.Refresh();
                dataGridView1.DataSource = db.GetDataSet1(strSql, "MOCTB").Tables["MOCTB"];

                if (MXCX.LX == "查看物料状况")
                {
                    this.dataGridView1.Columns["品名规格"].Width = 400;
                }
                else if (MXCX.LX == "查看排产状况")
                {
                    
                }
                else if (MXCX.LX == "查看计划完成状况")
                {
                    
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }
        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (QJCX.LX == "查看检验结果")
            {
                if (QJCX.DB == "IQC")
                {
                    string x1 = "";
                    string x2 = "";
                    string x3 = "";
                    string x4 = "";
                    string x5 = "";
                    string x6 = "";
                    string x7 = "";
                    string x8 = "";
                    x1 = dataGridView1["单别", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x2 = dataGridView1["单号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x3 = dataGridView1["序号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x4 = "IQC";
                    x5 = dataGridView1["次数", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x6 = dataGridView1["检验日期", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x7 = dataGridView1["备注", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x8 = dataGridView1["老编码", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    JYCX xx = new JYCX(x1, x2, x3, x4, x5,x6,x7,x8);
                    QMSJD f = new QMSJD();
                    f.sjddy += new QMSJD.SJDDY(textBox2_TextChanged);
                    f.Show(this);
                }

                if (QJCX.DB == "FQC")
                {
                    string x1 = "";
                    string x2 = "";
                    string x3 = "";
                    string x4 = "";
                    string x5 = "";
                    string x6 = "";
                    string x7 = "";
                    string x8 = "";
                    x1 = dataGridView1["单别", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x2 = dataGridView1["单号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x3 = dataGridView1["序号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x4 = "FQC";
                    x5 = dataGridView1["次数", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x6 = dataGridView1["检验日期", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x7 = dataGridView1["备注", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x8 = dataGridView1["老编码", dataGridView1.CurrentCell.RowIndex].Value.ToString();

                    JYCX xx = new JYCX(x1, x2, x3, x4, x5, x6,x7,x8);
                    QMFQC f = new QMFQC();
                    f.sjddy += new QMFQC.SJDDY(textBox2_TextChanged);
                    f.Show(this);
                }

                if (QJCX.DB == "OQC")
                {
                    string x1 = "";
                    string x2 = "";
                    string x3 = "";
                    string x4 = "";
                    string x5 = "";
                    string x6 = "";
                    string x7 = "";
                    string x8 = "";
                    x1 = dataGridView1["单别", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x2 = dataGridView1["单号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x3 = dataGridView1["序号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x4 = "OQC";
                    x5 = dataGridView1["次数", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x6 = dataGridView1["检验日期", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x7 = dataGridView1["备注", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x8 = dataGridView1["客户编号", dataGridView1.CurrentCell.RowIndex].Value.ToString();

                    JYCX xx = new JYCX(x1, x2, x3, x4, x5, x6,x7,x8);
                    QMFQC f = new QMFQC();
                    f.sjddy += new QMFQC.SJDDY(textBox2_TextChanged);
                    f.Show(this);
                }

                if (QJCX.DB == "PQC")
                {
                    string x1 = "";
                    string x2 = "";
                    string x3 = "";
                    string x4 = "";
                    string x5 = "";
                    string x6 = "";
                    string x7 = "";
                    string x8 = "";
                    x1 = dataGridView1["单别", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x2 = dataGridView1["单号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x3 = dataGridView1["序号", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x4 = "PQC";
                    x5 = dataGridView1["次数", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x6 = dataGridView1["检验日期", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x7 = dataGridView1["备注", dataGridView1.CurrentCell.RowIndex].Value.ToString();
                    x8 = dataGridView1["老编码", dataGridView1.CurrentCell.RowIndex].Value.ToString();

                    JYCX xx = new JYCX(x1, x2, x3, x4, x5, x6, x7, x8);
                    QMFQC f = new QMFQC();
                    f.sjddy += new QMFQC.SJDDY(textBox2_TextChanged);
                    f.Show(this);
                }

            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

    }
}
